package com.wealth.lottery.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wealth.lottery.entity.LotteryPrize;
import com.wealth.lottery.repository.LotteryPrizeDao;
import com.wealth.lottery.service.ILotteryPrizeService;

import iaas.service.impl.BaseServiceImpl;
/**
 * LotteryPrizeServiceImpl
 * @author lihang 2016-06-27
 *
 */
@Component
public class LotteryPrizeServiceImpl extends BaseServiceImpl<LotteryPrize> implements ILotteryPrizeService{
	Logger logger = Logger.getLogger(LotteryPrizeServiceImpl.class);
	@Autowired
	private LotteryPrizeDao lotteryPrizeDao;
	/**
	 * 查询某一活动下，当天可以参与抽奖的奖品
	 */
	@Override
	public List<LotteryPrize> getPrize(Long corpid, Long activityid) throws Exception{
		return lotteryPrizeDao.findByLotteryactivityIdAndCorpId(activityid, corpid);
	}
	/**得到被抽奖的奖品*/
	@SuppressWarnings("finally")
	@Override
	public LotteryPrize getluckPrize(Long activityid, int lucknum,Long corpid) throws Exception {
		LotteryPrize prize = null;
		try {
			List<LotteryPrize> prizeList =  lotteryPrizeDao.findByLotteryactivityIdAndLucknumAndCorpId(activityid, lucknum, corpid);
			if(prizeList.size()>0){
				if(prizeList.get(0).getStock()>0){
					prize = prizeList.get(0);
				}
			}
		} catch (Exception e) {
			logger.error(e);
		}finally {
			return prize;
		}
	}
	@Override
	public List<LotteryPrize> getPrizeByActivity(Long activityid, Long corpid) {
		return lotteryPrizeDao.findByLotteryactivityIdAndCorpId(activityid, corpid);
	}

}
